package com.heima.wemedia;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.wemedia.pojo.ApComment;
import com.heima.model.wemedia.dtos.ManageDto;
import com.heima.utils.baidu.HttpUtil;
import com.heima.wemedia.service.ManageService;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class test {
    @Test
    public void demo() {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined";
        try {
            String param = "text=" + URLEncoder.encode("腾讯是傻逼", "utf-8");
            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = "24.3df1f7f4bd7035edf9b766440e9fa045.2592000.1688982609.282335-34642874";
            String result = HttpUtil.post(url, accessToken, param);
            JSONObject jsonObject = JSON.parseObject(result);
            System.out.println(jsonObject.get("conclusion"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Autowired
    private ManageService manageService;

    @Test
    public void timeTest() {
        ManageDto manageDto = new ManageDto();

        manageDto.setPage(1);
        manageDto.setSize(5);
        PageResponseResult manage = manageService.manage(manageDto);
    }

    @Autowired
    private MongoTemplate mongoTemplate;

    @Test
    public void t2() {
        Query query = new Query(Criteria.where("entryId").is(1383828014629179393L));
        List<ApComment> apComments = mongoTemplate.find(query, ApComment.class);
        System.out.println("apComments = " + apComments);

}

    public void t1() {

        ArrayList<User> users = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            users.add(new User(i));
        }
        System.out.println("users = " + users);
        users.forEach(
                user -> {
                    user.setName("xiaoming");
                }
        );
        System.out.println("users = " + users);


    }


}

@Data
class User {
    public User(long age) {
        this.age = age;
    }

    private String name;
    private long age;
}
